#include "node.h"

Node::Node(const NodeIndex& index)
	: mcIndex(index)
{
	mpFrom = 0;
  h = 0;
  g = 0;
  f = 0;
}

Node::~Node(void)
{
}

const NodeIndex& Node::getIndex(void) const
{
	return mcIndex;
}

void Node::addNeighbor(Node* node)
{
  if (node != this) 
    mNeighbors[node->getIndex()] = node;
}

void Node::removeNeighbor(Node* node)
{
  NodeMap::iterator itr = mNeighbors.find(node->getIndex());
  if (itr != mNeighbors.end()) 
    mNeighbors.erase(itr);
}

void Node::clearNeighbors(void)
{
  mNeighbors.clear();
}

NodeMap& Node::getNeighbors(void)
{
  return mNeighbors;
}
  
Node* Node::getFromNode(void) const
{
	return mpFrom;
}

void Node::updateFromNode(Node* node)
{
}

float Node::computeG(Node* neighbor) const
{
  return (mcIndex.distTo(neighbor->getIndex()));
}

float Node::computeH(Node* goal) const    
{
  return (mcIndex.distTo(goal->getIndex()));
}

float Node::updateF(void) 
{
  return (f = g + h);
}
